package com.longteng.diamond.service.impl;


import com.longteng.diamond.dao.ProjectModuleMapper;
import com.longteng.diamond.dao.TestCaseMapper;
import com.longteng.diamond.domain.ProjectShareNode;
import com.longteng.diamond.domain.TestCase;
import com.longteng.diamond.po.RequestResult;
import com.longteng.diamond.service.ProjectShareInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator
 * DATE : 2018/7/28
 * TIME : 13:02
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Component
public class ProjectModuleInterface implements ProjectShareInterface {
    @Autowired
    ProjectModuleMapper projectModuleMapper;
    @Autowired
    TestCaseMapper testCaseMapper;

    /**
     * 新增模块
     *
     * @param projectShareNode
     * @return
     */
    @Override
    public RequestResult addProjectShare(ProjectShareNode projectShareNode) {
        RequestResult requestResult = new RequestResult();
        ProjectShareNode projectShareNodeDb = projectModuleMapper.findProjectModuleByName(projectShareNode);
        if (null != projectShareNodeDb) {
            requestResult.setSuccess(false);
            requestResult.setMsg("该模块已经存在,请更换一个名称");
            return requestResult;
        }
        projectModuleMapper.addProjectShareNode(projectShareNode);
        requestResult.setSuccess(true);
        return requestResult;
    }

    /**
     * 修改模块
     *
     * @param projectShareNode
     * @return
     */
    @Override
    public RequestResult updateProjectShare(ProjectShareNode projectShareNode) {
        RequestResult requestResult = new RequestResult();
        ProjectShareNode projectShareNodeDb = projectModuleMapper.findProjectModuleByName(projectShareNode);
        if (null != projectShareNodeDb) {
            Integer dbId = projectShareNodeDb.getId();
            Integer id = projectShareNode.getId();
            if (dbId.intValue() != id.intValue()) {
                requestResult.setSuccess(false);
                requestResult.setMsg("该模块已经存在,请更换一个名称");
                return requestResult;
            }
        }
        projectModuleMapper.updateProjectShareNode(projectShareNode);
        requestResult.setSuccess(true);
        return requestResult;
    }

    /**
     * 校验模块是否绑定测试用例了
     * @param id
     * @return
     */
    @Override
    public RequestResult deleteProjectShareCheck(Integer id) {
        RequestResult requestResult = new RequestResult();
        TestCase testCase = new TestCase();

//        testCaseMapper.getTestCase()
        projectModuleMapper.deleteProjectShareNode(id);
//        testCaseMapper.getTestCase();
//        List<ProjectShareNode> projectShareNodeList = interfaceHostMapper.findInterfaceHostById(id);
//        if (projectShareNodeList.size() > 0) {
//            requestResult.setSuccess(false);
//            requestResult.setMsg("该host已经绑定接口,确定删除吗?");
//        } else {
//            requestResult.setSuccess(true);
//        }
        return requestResult;
    }

    /**
     * 获取模块
     * @param projectId
     * @return
     */
    public List<ProjectShareNode> findProjectModuleByProjectId(Integer projectId) {
        return projectModuleMapper.findProjectModuleByProjectId(projectId);
    }

    /**
     * 删除模块
     *
     * @param id
     * @return
     */
    @Override
    public RequestResult deleteProjectShare(Integer id) {
        return null;
    }
}
